package com.ostrich.module_more.themes

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import com.ostrich.library_base.BaseMvvmFragment
import com.ostrich.library_common.utils.LoggerUtils
import com.ostrich.module_more.R
import com.ostrich.module_more.databinding.MoreFragmentThemesDataBinding
import com.ostrich.module_more.themes.adapter.ThemesDataAdapter
import com.ostrich.module_more.themes.entity.Tab
import com.ostrich.module_more.themes.entity.ThemesDataEntity


class ThemesDataFragment : BaseMvvmFragment<MoreFragmentThemesDataBinding,ThemesDataViewModel>() {
    private lateinit var tab:Tab
    private lateinit var themesDataAdapter: ThemesDataAdapter
    private val data:MutableList<ThemesDataEntity> = mutableListOf()
    override fun initView() {
        //获得tab数据
        tab = arguments?.getSerializable("tab") as Tab

        binding?.let {
            themesDataAdapter = ThemesDataAdapter(R.layout.more_item_themes_view,data)
            it.rv.adapter = themesDataAdapter
            it.rv.layoutManager = LinearLayoutManager(context)
            it.rv.setHasFixedSize(true)
        }

    }

    override fun initData() {

       viewModel.data(tab.id).observe(this){
           LoggerUtils.d(TAG,it.toString())
           themesDataAdapter.addData(it.itemList)
       }
    }

    override fun initListener() {

    }

    override fun bindLayout(): Int {
        return R.layout.more_fragment_themes_data
    }

    override fun getJVMClass(): Class<ThemesDataViewModel> {
        return ThemesDataViewModel::class.java
    }

    companion object{
        const val TAG = "ThemesDataFragment"
    }

}